<table id="dataTable"></table>

{include file="block/layui" /}

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?table=admin_user&id={{ d.id }}">
</script>

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('editUser')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '800px', height: '600px'}" title="修改管理员">修改</a><a href="{:url('delUser')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('addUser')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '800px', height: '600px'}" title="添加管理员">&nbsp;添加</a>
        <a data-href="{:url('status?val=1')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns layui-icon layui-icon-play" data-table="dataTable">&nbsp;启用</a>
        <a data-href="{:url('status?val=0')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns layui-icon layui-icon-pause" data-table="dataTable">&nbsp;禁用</a>
        <a data-href="{:url('delUser')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</script>

<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'username', title: '用户名', width: 100}
                ,{field: 'nick', title: '昵称', width: 100}
                ,{field: 'type', title: '职位', width: 100}
                ,{field: 'role_id', title: '角色', templet:function(d){
                    var str = '';
                    for(var i in d.has_roles) {
                        str += '<span class="layui-badge layui-bg-blue" style="margin-right:5px">'+d.has_roles[i].name+'</span>';
                    }
                    return str;
                }}
                ,{field: 'shop', title: '门店', width: 120,templet:function(d){
                    return d.has_shop.name;
                }}
                ,{field: 'mobile', title: '手机', width: 120}
                ,{field: 'last_login_time', width: 150, title: '最后登陆'}
                ,{field: 'last_login_ip', title: '登陆IP', width: 120}
                ,{field: 'status', title: '状态', width: 95, templet: '#statusTpl'}
                ,{title: '操作', templet: '#buttonTpl', width:110}
            ]]
        });
    });
</script>
